package com.lc.user.express.httpserver;

import com.lc.user.express.model.AddrModel;
import com.lc.user.express.model.FurnitureModel;
import com.lc.user.express.model.UsedRouteModel;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/31.我的常用路线
 */
@HttpInlet(Net.GET_MY_ADDR)
public class GetMyAddr extends ZJDBAsyGet<GetMyAddr.Info> {
    public String userid;

    public GetMyAddr(String userid,AsyCallBack listener) {
        super(listener);
        this.userid = userid;
    }

    @Override
    protected Info parser(JSONObject object) {
        if (object.optInt("message") == 1) {
            Info info = new Info();
            JSONArray array = object.optJSONArray("list");
            if(array != null){
                for (int i = 0; i<array.length(); i++){
                    JSONObject jsonObject = array.optJSONObject(i);
                    UsedRouteModel model = new UsedRouteModel();
                    model.setRouteId(jsonObject.optString("id"));
                    model.setName(jsonObject.optString("title"));
                    model.setStartAddr(jsonObject.optString("address"));
                    model.setEndAddrCount(jsonObject.optInt("number"));
                    info.dataList.add(model);

                }

            }
            return info;
        }
        return null;
    }

    public static class Info {
        public List<UsedRouteModel> dataList = new ArrayList<>();
    }
}
